<?php

namespace App\Models\Api;

class ResumeSend extends ApiModel
{
    //表名
    protected $table = 'resume_send';

    protected $guarded = [];

    //简历投递的职位
    public function company_job()
    {
        return $this->hasOne(CompanyJob::class, 'id', 'job_id')
            ->whereBetween('job_status', [0, 2])
            ->select('id', 'job_title');
    }

    public function getJobTitleAttribute()
    {
        return $this->company_job ? $this->company_job->job_title : '';
    }

    //简历投递的公司
    public function company_basic()
    {
        return $this->hasOne(CompanyBasic::class, 'id', 'com_id')
            ->select('id', 'company_name');
    }

    public function getCompanyNameAttribute()
    {
        return $this->company_basic ? $this->company_basic->company_name : '';
    }

    //企业用来查看投递简历
    public function resume()
    {
        return $this->hasOne(Resume::class, 'id', 'resume_id')
            //完全保密不给查看
            ->where('bkresume_status', '!=', 3)
            ->with('homeaddress_area_name')
            ->select('id', 'name', 'sex', 'birthday', 'education',
                'updatetime', 'intentionjobs', 'avatar', 'homeaddress',
                'chkphoto_open');
    }

    public function getTimeAttribute()
    {
        return $this->updated_at->format('Y-m-d');
    }

    public function getAvatarAttribute()
    {
        if (!$this->resume || $this->resume->chkphoto_open == 1) {//隐藏头像
            return '';
        }
        return $this->resume->avatar;
    }

    public function getNameAttribute()
    {
        return $this->resume ? $this->resume->name : '';
    }

    public function getSexAttribute()
    {
        return $this->resume ? $this->resume->sex : '';
    }

    public function getAgeAttribute()
    {
        return $this->resume ? $this->resume->age : '';
    }

    public function getIntentionjobsAttribute()
    {
        return $this->resume ? $this->resume->intentionjobs : '';
    }

    public function getHomeaddressNameAttribute()
    {
        return $this->resume ? $this->resume->homeaddress_name : '';
    }

    public function getEducationNameAttribute()
    {
        return $this->resume ? $this->resume->education_name : '';
    }

}
